// Two function need to be implemented , messageList_handler & messageList_handler_configMode
// used GM Variables
// null
Curop = CONFIG.messageoption;
AutoRead = CONFIG.auto_read;


function messageList_handler(){
    var query = window.location.search;
    if(query == "?type=1&isread=0"){ //in list page
        var trs = $x("//table[@id='ct1']/tbody/tr");
        if(trs.length >2){
            var link = trs[1].childNodes[2].childNodes[0].getAttribute("href");
            var title = trs[1].childNodes[2].childNodes[0].innerHTML;
            log("正在讀取消息:'"+title+"',頁面跳轉中...");
            clickLink(link);      
        }else{
            log("消息閱讀已經完成,正在跳轉回首頁...");
            clickLink("/mindex");
			
        }
        return;
    }
    if(query.indexOf("eventSubmit_detail=true")>-1){ // in message content page
        //log("消息閱讀完成,跳轉回未讀消息列表頁面...");
		log("消息閱讀完成,正在按配置规则进行相应操作");
			switch(Curop){
				case "1":
					log('按配置已保留信息，跳轉回未讀消息列表頁面...');
					clickLink("/messageList?type=1&isread=0");//保留，返回未读列表
					break;
				case "2":
					log('按配置進行删除信息...');
					var urlstring = query.split("=");//messageList?type=1&eventSubmit_detail=true&oid=7765563
					clickLink('/messageList?eventSubmit_delete=true&oid='+urlstring[3]+'&type=1');
					break;
				default :
					log('按配置对短信进行随机操作...');
					RandomNum = Math.round(Math.random()*10);
					if(RandomNum<=5){
						log('本次操作為刪除');
						var urlstring = query.split("=");
						clickLink('/messageList?eventSubmit_delete=true&oid='+urlstring[3]+'&type=1');
					}else{
						log('本次操作為保留');
						clickLink("/messageList?type=1&isread=0");//保留，返回未读列表
					}
					break;
			}
        return;
    }
    log("消息頁面沒有任何需要處理的邏輯,正在跳轉回首頁...");
    clickLink("/mindex");
}

function messageList_handler_configMode(){
    log("系統將自動讀取所有短消息.無需手動配置任何選項.");
	
	$('div.col2 > h1').after('<div id="op"><p>'+getDSIconPath()+'设置短信阅读完成后的操作:<input type=\'radio\' name=\'msgop\' value=\'1\'>保留&nbsp;&nbsp;<input type=\'radio\' name=\'msgop\' value=\'2\'>删除&nbsp;&nbsp;<input type=\'radio\' name=\'msgop\' value=\'3\'>随机</p></div>');
	$('div.col2 > h1').after('<div id="ar"><p>'+getDSIconPath()+'設置是否自動閱讀短消息：<input type=\"radio\" name=\"autoread\" value=\"true\"/>自動閱讀&nbsp;&nbsp;<input type=\"radio\" name=\"autoread\" value="false"/>不閱讀</p></div>');
	
	$("input[@name='autoread'][@value='"+AutoRead+"']").attr("checked","checked");
	$("input[@name='msgop'][@value='"+Curop+"']").attr("checked","checked");
	$("input[@name='msgop'][@type='radio']").click(function(){
		var op = $(this).val();
		CONFIG.messageoption = op;

	});
	$("input[@name='autoread'][@type='radio']").click(function(){
		var ar = $(this).val();
		CONFIG.auto_read = ar;

	});
}


